package com.meepo.feed.message

import android.os.Bundle
import android.view.View
import com.meepo.basic.router.RouterManager
import com.meepo.basic.router.RouterManager.FeedModule.FeedMessageHistory_Path
import com.meepo.basic.schema.user.User
import com.meepo.basic.schema.user.User.Companion.SELF
import com.meepo.basic.components.view.MeepoActivity
import com.meepo.feed.R
import com.meepo.framework.design.helper.StatusBarHelper
import com.meepo.framework.design.tabs.ViewPagerHelper
import com.meepo.framework.design.tabs.buildins.commonnavigator.CommonNavigator
import com.meepo.framework.design.tabs.sample.TextTab
import com.meepo.framework.design.tabs.sample.navadapters.ColorTransitionNavigatorAdapter
import com.meepo.framework.design.viewpager.adapter.DefaultFragmentStatePagerAdapter
import com.xiaojinzi.component.anno.RouterAnno
import com.xiaojinzi.component.support.ParameterSupport
import kotlinx.android.synthetic.main.message_history_activity.back_iv
import kotlinx.android.synthetic.main.message_history_activity.header_rl
import kotlinx.android.synthetic.main.message_history_activity.magic_indicator
import kotlinx.android.synthetic.main.message_history_activity.view_pager

@RouterAnno(hostAndPath = FeedMessageHistory_Path)
class MessageHistoryActivity : MeepoActivity() {

    private var mTabIndex: Int = 0

    override fun initView(view: View, savedInstanceState: Bundle?) {
        StatusBarHelper.immerse(this, header_rl)

        mTabIndex = ParameterSupport.getInt(intent, "tabIndex") ?: 0

        val tabs = arrayListOf("@我的", "新增粉丝", "系统通知").map {
            TextTab(
                it, it,
                selectedTextColor = resources.getColor(R.color.primary_color),
                unSelectedTextColor = resources.getColor(R.color.primary_text_color)
            )
        }

        val fragments = listOf(
            RouterManager.FeedModule.routeToCommentList(atUserId = SELF, forDisplay = true),
            RouterManager.UserModule.routeToUserListFragment(followUserId = SELF, relationType = User.RELATION_TYPE_FOLLOW),
            SystemNotifyFragment()
        )


        magic_indicator.navigator =
            CommonNavigator(
                this,
                ColorTransitionNavigatorAdapter(tabs) { index -> view_pager.currentItem = index }, true
            )

        view_pager.adapter = DefaultFragmentStatePagerAdapter(supportFragmentManager, fragments)

        ViewPagerHelper.bind(magic_indicator, view_pager)

        view_pager.currentItem = mTabIndex

        back_iv.setOnClickListener { finish() }
    }

    override fun initData() {
    }

    override fun setUpContentLayout(): Int = R.layout.message_history_activity

}